import { NestFactory } from '@nestjs/core';
import { NestExpressApplication } from '@nestjs/platform-express';
import { utilities, WinstonModule } from 'nest-winston';
import { transports, format } from 'winston';
import DailyRotateFile from 'winston-daily-rotate-file';

import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule, {
    logger: WinstonModule.createLogger({
      level: 'info', // 默认日志级别
      format: format.combine(
        format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
        utilities.format.nestLike('NEST'),
      ),
      transports: [
        new transports.Console(),
        new DailyRotateFile({
          filename: 'logs/%DATE%.log',
          datePattern: 'YYYY-MM-DD',
          maxFiles: '30d',
          level: 'info',
          format: format.combine(
            format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
            utilities.format.nestLike('NEST', { colors: false }),
          ),
        }),
      ],
    }),
  });

  app.setGlobalPrefix('api/v1/');

  app.useStaticAssets(`${__dirname}/../static`, { prefix: '/store' });

  await app.listen(process.env.PORT ?? 3000, '0.0.0.0');
}
void bootstrap();
